

from util.selenium.webdriver.common.by import By

from base.BaseMethod import BM
from util.DataQuery.FormDataDecorator import FormDataDecorator

# # # # # # # #        填写申请书封皮             completed                # # # # # # # # # # #


class WriteApplicationCover():
    form_btn_loc = (By.LINK_TEXT, '申请书封皮')
    title_loc = (By.CSS_SELECTOR, 'h2.text-center')
    content_iframe_loc = (By.CSS_SELECTOR, "#innocomFrame")
    # cercification_body 认定机构
    cer_body_select_loc = (By.CSS_SELECTOR, 'select#centersAuthorized')
    # application_date

    application_date_loc = (By.CSS_SELECTOR, 'input#hadate')
    date_js_str = "document.getElementById('hadate').removeAttribute('readonly')"
    save_btn_loc = (By.CSS_SELECTOR, 'button#saver.green')
    print_btn_loc = (By.CSS_SELECTOR, 'button#print')

    # 写代码时方便提示, 基本方法完成后删除
    # driver = driver
    def __init__(self, driver=None):
        self.driver = driver

    @property
    def class_name(self):
        return self.__class__.__name__

    @FormDataDecorator
    def main(self, cert_org='', app_date=''):
        BM.click(driver=self.driver, ele_loc=self.form_btn_loc)
        BM.cut_over_frame(driver=self.driver, selector_loc=self.content_iframe_loc)
        BM.wait(driver=self.driver, ele_loc=self.title_loc)
        BM.select_value_choice(selector_loc=self.cer_body_select_loc, text_value=cert_org, driver=self.driver)
        self.driver.execute_script(self.date_js_str)
        BM.input(driver=self.driver, ele_loc=self.application_date_loc, keys=app_date)
        BM.global_click_btn(btn_loc=self.save_btn_loc, driver=self.driver)
